package com.reggie.service.impl;

import com.reggie.dao.SetmealDishDao;
import com.reggie.pojo.Dish;
import com.reggie.pojo.SetmealDish;
import com.reggie.service.SetMealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SetMealDishServiceImpl implements SetMealDishService {

    @Autowired
    private SetmealDishDao setmealDishDao;
    @Override
    public void addSetMealDish(SetmealDish setmealDish) {
        setmealDishDao.insert(setmealDish);
    }

    @Override
    public void deleteBySetMealId(Long... setmeals) {
        for (Long setmeal : setmeals) {
            setmealDishDao.deleteBySetmealId(setmeal);
        }
    }

    @Override
    public List<SetmealDish> selectBySetmealId(Long id) {
        return setmealDishDao.selectBySetmealId(id);
    }

    @Override
    public void updateSetMealDish(List<SetmealDish> setmealDishs) {
        //先将这个套餐中的所有的菜品全都删除
        setmealDishDao.deleteBySetmealId(setmealDishs.get(0).getSetmealId());
        //执行添加操作
        for (SetmealDish setmealDish : setmealDishs) {
            setmealDishDao.insert(setmealDish);
        }
    }
}
